﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Movie.DAL
{
   public class SeatDAL
    {
       public static List<Modal.Seat> GetSeat(int SchuID) 
       {
           //"select *,(select seatid from orderseat where orderid in(select orderid from orders where scheduleid={0})) as seatState from PriceSeat where roomid=(select roomID from Schedule where scheduleid={0})"

           //"select * from (select * from PriceSeat where  roomid=(select RoomID from Schedule where scheduleId={0})) t1 left outer join(select seatid as seatSate from orderseat where orderid in(select orderid from orders where scheduleid= {0})) t2 on t1.SeatID=t2.seatSate"
           string sql = string.Format("select * from (select * from PriceSeat where  roomid=(select RoomID from Schedule where scheduleId={0})) t1 left outer join(select seatid as seatState from orderseat where orderid in(select orderid from orders where scheduleid= {0})) t2 on t1.SeatID=t2.seatState", SchuID);
       SqlDataReader reder = sqlHelper2.ExcuteReader(sql);
       List<Modal.Seat> list = new List<Modal.Seat>();
       while (reder.Read())
       {
           Modal.Seat seat = new Modal.Seat();
           seat.SeatID = Convert.ToInt32(reder["SeatID"]);
           seat.RoomID = Convert.ToInt32(reder["RoomID"]);
           seat.RowNum = Convert.ToInt32(reder["RowNum"]);
           seat.ColNum = Convert.ToInt32(reder["ColNum"]);
           seat.IsValid = Convert.ToBoolean(reder["IsValid"]);

           if (reder.IsDBNull(reder.GetOrdinal("seatState")))
           {
               seat.SeatState = Modal.SeatState.UNSELECT;
           }
           else 
           {
               seat.SeatState = Modal.SeatState.SELECT;
           }
           list.Add(seat);
           
       }
       return list;
       
       
       }

    }
}
